/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package filmlibrary.web;

import java.util.HashMap;
import java.util.Locale;
import java.util.logging.Logger;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.ExternalContext;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;


/**
 *
 * @author karol
 */
@ManagedBean
@SessionScoped
public class LocaleBean {
    private static final Logger logger = Logger.getLogger("filmlibrary.web.LocaleBean");
    private HashMap<String, Locale> locales = null;
    private Locale locale = FacesContext.getCurrentInstance().getViewRoot().getLocale();

    public Locale getLocale() {
        return locale;
    }

    public LocaleBean() {
        locales = new HashMap<String, Locale>(2);
        locales.put("PL", new Locale("pl"));
        locales.put("EN", new Locale("en"));
    }
    public String getLanguage() {
        return locale.getLanguage();
    }

    public void setLanguage(String language) {
        locale = new Locale(language);
        FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
        
    }
    public String change(String language) {
        locale = new Locale(language);
        FacesContext.getCurrentInstance().getViewRoot().setLocale(locale);
        FacesContext ctx = FacesContext.getCurrentInstance();
HttpServletRequest servletRequest = (HttpServletRequest) ctx.getExternalContext().getRequest();
// returns something like "/myapplication/home.faces"
String fullURI = servletRequest.getRequestURI();

        return fullURI;

    }


}